package main

import (
	"fmt"
	"net/http"

	"fancy_web/data"
)

func index(w http.ResponseWriter, r *http.Request) {
	threads, err := data.Threads()
	if err != nil {
	} else {
		sess, err := session(w, r)
		user, err := sess.GetUser()
		if err == nil {
			setUser(user.Id, &user)
		}
		fmt.Println("index err = ", err, sess)
		if err != nil {
			generateHTML(w, threads, "layout", "public.navbar", "index")
		} else {
			generateHTML(w, threads, "layout", "private.navbar", "index")
		}
	}
}

func err(w http.ResponseWriter, r *http.Request) {
	vals := r.URL.Query()
	fmt.Println("err, val = ", vals)
	_, err := session(w, r)
	if err != nil {
		generateHTML(w, vals.Get("msg"), "layout", "public.navbar", "error")
	} else {
		generateHTML(w, vals.Get("msg"), "layout", "private.navbar", "error")
	}
}
